import axios from "@/utils/http";
//数据
const state = {
  //数据定义处
  // 获取药品总库存表格默认数据
  defaultData: [],
  tableTotal: 1,
  // 获取批次库存表格默认数据
  batchInventoryData: [],
  batchInventoryTotal: 1,
};

const getters = {
  //修饰后的数据获取方法
  // 获取药品总库存表格默认数据
  getDrugStockData(state: any) {
    let arr = state.defaultData;
    return arr;
  },
  // 获取批次库存表格默认数据
  getBatchInventoryData(state: any) {
    let arr = state.batchInventoryData;
    return arr;
  },
};

const mutations = {
  // 获取药品总库存表格默认数据
  setDrugStockData(state: any, page: any) {
    axios({
      url: "/medicine/stock/findAllDrug",
      method: "get",
      params: {
        currentPage: page.currentPage,
        pageSize: page.pageSize,
        drugName: page.drugName,
      },
    })
      .then((res: any) => {
        console.log("药品总库存表格数", res);
        state.defaultData = res.data.data;
        state.tableTotal = res.data.count;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  // 获取批次库存表格默认数据
  setBatchInventoryData(state: any, page: any) {
    axios({
      url: "/medicine/stock/findAllOrder",
      method: "get",
      params: {
        currentPage: page.currentPage,
        pageSize: page.pageSize,
        drugName: page.drugName,
        status: page.status,
      },
    })
      .then((res: any) => {
        console.log("批次库存", res);
        state.batchInventoryData = res.data.data;
        state.batchInventoryTotal = res.data.count;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  // 调价
  setPriceData(state: any, page: any) {
    axios({
      url: "/medicine/stock/updatePrice",
      method: "post",
      params: {
        allStock: page.allStock,
        price: page.price,
        drugName: page.drugName,
      },
    })
      .then((res: any) => {
        console.log("批次库存", res.data.data);
        // state.defaultData = res;
        // state.tableTotal = res.data.count;
      })
      .catch((err) => {
        console.log(err);
      });
  },
};

const actions = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
